package qc.module.iot.protocol.sl427;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * SL427数据帧功能码枚举
 *
 * @author QuCheng Tech
 * @since 2025/11/12
 */
@Getter
@AllArgsConstructor
public enum SL427_FrameFunctionCodeEnum {
    UN_DEFINE(0, "备用"),//保留备用
    HEART_BEAT(0x02, "链路检测"),//链路检测，心跳数据
    SET_PARAM_10H(0x10, "设置地址"),
    SET_PARAM_11H(0x11, "设置时钟"),
    SET_PARAM_12H(0x12, "设置工作模式"),
    SET_PARAM_15H(0x15, "设置本次充值量"),
    SET_PARAM_16H(0x16, "设置剩余水量报警值"),
    SET_PARAM_17H(0x17, "设置水位基值上下限"),
    SET_PARAM_18H(0x18, "设置水压上下限"),
    SET_PARAM_19H(0x19, "设置水质参数种类上限值"),
    SET_PARAM_1AH(0x1A, "设置水质参数种类下限值"),
    SET_PARAM_1BH(0x1B, "设置水量初始值"),
    SET_PARAM_1CH(0x1C, "设置引导码长"),
    SET_PARAM_1DH(0x1D, "设置转发地址"),
    SET_PARAM_1EH(0x1E, "设置自动切换自报状态"),
    SET_PARAM_1FH(0x1F, "设置流量参数上限值"),
    SET_PARAM_20H(0x20, "设置监测参数启报阈值及固态存储时间段间隔"),
    SET_PARAM_30H(0x30, "设置IC卡功能有效"),
    SET_PARAM_31H(0x31, "设置取消IC卡功能有效"),
    SET_PARAM_32H(0x32, "设置定值功能投入"),
    SET_PARAM_33H(0x33, "设置定值功能退出"),
    SET_PARAM_34H(0x34, "设置定值量"),
    QUERY_PARAM_50H(0x50, "查询地址"),
    QUERY_PARAM_51H(0x51, "查询时钟"),
    QUERY_PARAM_52H(0x52, "查询工作模式"),
    QUERY_PARAM_53H(0x53, "查询自报种类及时间间隔"),
    QUERY_PARAM_54H(0x54, "查询实时数据种类"),
    QUERY_PARAM_55H(0x55, "查询成功充值量和现有剩余水量"),
    QUERY_PARAM_56H(0x16, "查询剩余水量报警值"),
    QUERY_PARAM_57H(0x17, "查询水位基值上下限"),
    QUERY_PARAM_58H(0x18, "查询水压上下限"),
    QUERY_PARAM_59H(0x19, "查询水质参数种类上限值"),
    QUERY_PARAM_5AH(0x1A, "查询水质参数种类下限值"),
    QUERY_PARAM_5DH(0x1D, "查询事件记录"),
    QUERY_PARAM_5EH(0x1E, "查询状态和报警状态"),
    QUERY_PARAM_5FH(0x1F, "查询水泵电机实时工作数据"),
    QUERY_PARAM_60H(0x60, "查询引导码长"),
    QUERY_PARAM_61H(0x61, "查询实时图像"),
    QUERY_PARAM_62H(0x62, "查询转发地址"),
    QUERY_PARAM_63H(0x63, "查询中继站状态和切换记录"),
    QUERY_PARAM_64H(0x64, "查询流量参数上限值"),
    QUERY_PARAM_65H(0x65, "查询主备信道类型及中心站地址"),
    REPORT_DATA_81H(0x81, "自报报警数据"),
    REPORT_DATA_82H(0x82, "自报人工置数"),
    REPORT_DATA_83H(0x83, "自报图片数据"),
    REPORT_DATA_84H(0x84, "自报输入电压数据"),
    CONTROL_90H(0x90, "复位参数和状态"),
    CONTROL_91H(0x91, "清空历史数据单元"),
    CONTROL_92H(0x92, "启动水泵或阀门"),
    CONTROL_93H(0x93, "关闭水泵或阀门"),
    CONTROL_94H(0x94, "切换通信机"),
    CONTROL_95H(0x95, "切换工作机"),
    CONTROL_96H(0x96, "修改密码"),
    SET_PARAM_A0H(0xA0, "设置实时数据种类"),
    SET_PARAM_A1H(0xA1, "设置自报种类及时间将"),
    SET_PARAM_A2H(0xA2, "设置主备信道类型及中心站地址"),
    QUERY_PARAM_B0H(0xB0, "查询实时值"),
    QUERY_PARAM_B1H(0xB1, "查询固态存储数据"),
    QUERY_PARAM_B2H(0xB2, "查询内存自报数据"),
    REPORT_DATA_C0H(0xC0, "自报实时数据");//自报实时数据

    @EnumValue
    private int index;
    private String name;

    @Override
    public String toString() {
        if (this != null)
            return this.name;

        return null;
    }

    /**
     * 根据int数值获取对应的枚举
     *
     * @param index 数值，限制为1字节
     * @return qc.module.iot.protocol.sl427.SL427_FrameFunctionCodeEnum
     * @author QuCheng Tech
     * @since 2025/11/9
     */
    public static SL427_FrameFunctionCodeEnum getSL427_FrameFunctionCodeEnum(int index) {
        if (index > 0x0) {
            int byteIntValue = index & 0xFF;//传入的值限制为1字节，最大0xFF
            if (byteIntValue > 0x0) {
                for (SL427_FrameFunctionCodeEnum item : SL427_FrameFunctionCodeEnum.values()) {
                    if (item.getIndex() == byteIntValue) {//判断序号使用getIndex，判断内容使用getName
                        return item;
                    }
                }
            }
        }
        return SL427_FrameFunctionCodeEnum.UN_DEFINE;
    }
}
